package com.example.home.loveDonation.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.home.R;
import com.example.home.loveDonation.bean.DonateListBean;

import java.util.List;

import static com.example.home.tool.StaticActi.ip;

public class CaringwelfarelistApter extends RecyclerView.Adapter<CaringwelfarelistApter.MyHoldy> {
    private Context context ;
    private List<DonateListBean.RowsBean> list;
    private View view;

    public CaringwelfarelistApter(Context context, List<DonateListBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public MyHoldy onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.item_caringwelfarelist,null);
        return new MyHoldy(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyHoldy holder, int position) {

        Glide.with(context).load(ip+list.get(position).getImgUrl()).into(holder.imgUrl);
        holder.name.setText("公益名称："+list.get(position).getName());
        holder.author.setText("发布组织："+list.get(position).getAuthor());
        holder.donateCount.setText("捐赠人数："+list.get(position).getDonateCount());
        holder.moneyNow.setText("已筹善款："+list.get(position).getMoneyNow());
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class MyHoldy extends RecyclerView.ViewHolder {
        ImageView imgUrl;
        TextView name;
        TextView author;
        TextView donateCount;
        TextView moneyNow;
        public MyHoldy(@NonNull View itemView) {
            super(itemView);
            imgUrl = itemView.findViewById(R.id.imgUrl);
            name = itemView.findViewById(R.id.name);
            author = itemView.findViewById(R.id.author);
            donateCount = itemView.findViewById(R.id.donateCount);
            moneyNow = itemView.findViewById(R.id.moneyNow);
        }
    }
}
